package com.iteaj.iboot.msn.iot.collect.action;

import com.iteaj.iboot.msn.iot.collect.CollectException;
import com.iteaj.iboot.msn.iot.consts.IotConsts;
import com.iteaj.iboot.msn.iot.dto.CollectTaskDto;
import com.iteaj.iboot.msn.iot.dto.DeviceDto;
import com.iteaj.iboot.msn.iot.entity.Device;
import com.iteaj.iboot.msn.iot.entity.Signal;
import com.iteaj.iot.modbus.server.dtu.ModbusRtuForDtuCommonProtocol;
import org.springframework.util.StringUtils;

import java.util.function.Consumer;

/**
 * modbus rtu for dtu采集动作
 */
public class ModbusRtuForDTUCollectAction extends CollectAction {

    @Override
    public String getName() {
        return IotConsts.COLLECT_ACTION_MODBUS_DTU_RTU;
    }

    @Override
    public String getDesc() {
        return "使用DTU的modbus rtu协议";
    }

    @Override
    public void validate(Signal signal) {
        super.validate(signal);
    }

    @Override
    public void validate(DeviceDto device) {
        super.validate(device);

        if(!StringUtils.hasText(device.getDeviceSn())) {
            throw new CollectException("未指定设备编号");
        }
    }

    @Override
    protected void doExec(CollectTaskDto taskDto, DeviceDto device, Signal signal, Consumer<String> call) {
//        ModbusRtuForDtuCommonProtocol.buildRead02(device.getDeviceSn(), ).request();
    }
}
